/*
** jobmgr.c for 42sh in /home/guina_b/
** 
** Made by benoit guina
** Login   <guina_b@epitech.net>
** 
** Started on  Fri Jan 01 00:00:00 2010 benoit guina
** Last update Fri Jan 01 00:00:00 2010 benoit guina
*/

#include "list.h"
#include "error.h"
#include "job.h"
#include "jobmgr.h"

t_jobmgr *jobmgr_get()
{
  static t_jobmgr jobmgr;

  return (&jobmgr);
}

t_jobmgr *jobmgr_init()
{
  t_jobmgr *r;

  r = jobmgr_get();
  r->jobs = 0;
  return (r);
}

void jobmgr_free(t_jobmgr *jobmgr)
{
  list_apply(jobmgr->jobs, (void (*)())job_free);
}

int jobmgr_add_job(t_job *job, t_jobmgr *jobmgr)
{
  /*"job->num = jobmgr_define_job_num(jobmgr->jobs);" ?*/
  list_add((void **)&jobmgr->jobs, job);
  return (0);
}

int jobmgr_set_job(t_jobmgr *jobmgr, int job, e_job_status status)
{
  t_job *j;

  if ((j = list_get(jobmgr->jobs, job)))
    return (job_set_status(j, status));
  error_print(SH_ERR_JOB_INVALID, job);
  return (0);
}
